package com.eqs.enterprisequestionnaire.controller;


import com.eqs.enterprisequestionnaire.model.pojo.Option;
import com.eqs.enterprisequestionnaire.result.R;
import com.eqs.enterprisequestionnaire.service.OptionService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/option")
public class OptionController {
    @Resource
    private OptionService optionservice;

    /**
     * 新增
     */
    @PostMapping("/add")
    public R<String> add(@RequestBody Option option){
        optionservice.save(option);
        return R.success("success");
    }
    /**
     * 删除(根据id)
     */
    @DeleteMapping("/delete/{id}")
    public R<String>deleteById(Integer id) {
        optionservice.removeById(id);
        return R.success("success");
    }
    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public R<String> deleteBatch(@RequestBody List<Integer> ids){
        optionservice.removeByIds(ids);
        return R.success("success");
    }
    /**
     * 修改(根据id)
     */
    @PutMapping("/update")
    public R<String> update(@RequestBody Option option){
        optionservice.updateById(option);
        return R.success("success");
    }
    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public R<Option> selectById(Integer id){
        Option option = optionservice.getById(id);
        return R.success(option);
    }
    /**
     * 查询所有(可根据属性查询出list)
     */
    @GetMapping("/selectAll")
    public R<List<Option>> selectAll(@RequestBody Option option){
        List<Option> options =  optionservice.selectAll(option);
        return R.success(options);
    }
}
